package com.baitiaojun.web.config;

import com.baitiaojun.common.constants.WebFilterOrderEnum;
import com.baitiaojun.web.core.filter.ServletRequestCacheFilter;
import com.baitiaojun.xss.config.XssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * web组件配置
 */
@AutoConfiguration
public class WebAutoConfiguration{

    @Autowired
    private WebCacheProperties webCacheProperties;

    /**
     * json参数缓存过滤器
     * @return
     */
    @Bean
    public FilterRegistrationBean<ServletRequestCacheFilter> registerServletRequestCacheFilter() {
        FilterRegistrationBean<ServletRequestCacheFilter> filterRegistrationBean
                = new FilterRegistrationBean<>(new ServletRequestCacheFilter(webCacheProperties));
        filterRegistrationBean.setOrder(WebFilterOrderEnum.REQUEST_BODY_CACHE_FILTER);
        return filterRegistrationBean;
    }
}
